package com.ext.aic.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.ext.aic.R;
import com.ext.aic.adapter.IndustryAdapter;
import com.ext.aic.beans.SecondIndustry;
import com.ext.aic.databinding.IndustryListLayoutBinding;

import java.util.List;

import lombok.Setter;

public class IndustryListFragment extends BaseFragment {

    private IndustryListLayoutBinding binding;
    private IndustryAdapter adapter;
    @Setter
    private List<SecondIndustry> items;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.industry_list_layout, container, false);
        binding = IndustryListLayoutBinding.bind(view);
        initView();
        return binding.getRoot();
    }

    private void initView() {
        binding.industryListRv.setLayoutManager(new LinearLayoutManager(getContext()));
        DividerItemDecoration divider = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        divider.setDrawable(ContextCompat.getDrawable(getContext(), R.drawable.divider_transparent));
        binding.industryListRv.addItemDecoration(divider);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        adapter = new IndustryAdapter();
        adapter.setItems(items);
        binding.industryListRv.setAdapter(adapter);
    }
}